package practice_0527;

import java.util.Random;
import java.util.Scanner;

public class practice05 {
    public static void main(String[] args) {
        T1 t1 = new T1();
        T2 t2 = new T2(t1);
        t1.start();
        t2.start();

    }
}
class T1 extends Thread{
    private boolean flag = true;

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    @Override
    public void run() {
        Random random = new Random();
        while(flag){
            System.out.println((int)(Math.random() * 100));
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

        }

    }
}

class T2 extends Thread{
     Scanner scan = new Scanner(System.in);
     T1 t;

    public T2(T1 t) {
        this.t = t;
    }

    @Override
    public void run() {
        char ans = ' ';
        while(true){
            System.out.println("输入命令");
            ans = scan.next().toUpperCase().charAt(0);
            if(ans =='Q'){
                t.setFlag(false);
                break;
            }
        }


    }
}